﻿//using Autodesk.Revit.Attributes;
//using Autodesk.Revit.UI; 
//using System;
//using System.Collections.Generic;
//using System.Drawing;
//using System.IO;
//using System.Linq;
//using System.Reflection;
//using System.Text;
//using System.Threading.Tasks;
//using System.Windows;
 

//namespace AvaloniaDemo
//{
//    [TransactionAttribute(TransactionMode.Manual)]
//    [Regeneration(RegenerationOption.Manual)]
//    internal class Ribbon : IExternalApplication
//    {

//        public static string assemblyPath = Assembly.GetExecutingAssembly().Location;
//        public static string assemblyDir = Path.GetDirectoryName(assemblyPath) + "\\";


//        public Result OnShutdown(UIControlledApplication application)
//        {
//            throw new NotImplementedException();
//        }

//        public Result OnStartup(UIControlledApplication application)
//        { 
//            //ImageSource imageSource = Func.ChangeBitmapToImageSource(Resource.ICON_ALL); 
//            //添加一个新的选项卡

//            string ribbonTabName = "SEPD电气工具";
//            application.CreateRibbonTab(ribbonTabName);

//            RibbonPanel toolRibbonPanel = application.CreateRibbonPanel(ribbonTabName, "辅助");
//            //=================================
//            SplitButton toolSplitButtonData = CreateSplitButton
//            (toolRibbonPanel, "1-0-0", "toolSplitButtonData");
//            //-------------------------- ss
//            CreateSplitPushButton(toolSplitButtonData, GetDllPath("SEPD.GeneralUtils.链接重载.dll"), "1-0-2",
//            "链接重载\n多选", "SEPD.GeneralUtils.链接重载.ReCreateLevelBySelectLinkCommand", imageSource);

//            return Result.Succeeded;
//        }

//        /// <summary>
//        /// 建立分裂按钮
//        /// </summary>
//        /// <param name="ribbonPanel"></param>
//        /// <param name="code"></param>
//        /// <param name="splitButtonName"></param>
//        /// <returns></returns>
//        public SplitButton CreateSplitButton(RibbonPanel ribbonPanel, string code, string splitButtonName)
//        {
//            SplitButtonData _SpliteButtonData = new SplitButtonData(code + splitButtonName,
//              splitButtonName);
//            SplitButton _SplitButton = ribbonPanel.AddItem(_SpliteButtonData) as SplitButton;
//            _SplitButton.IsSynchronizedWithCurrentItem = false;
//            return _SplitButton;
//        }

//        /// <summary>
//        /// 建立分裂按钮的子按钮
//        /// </summary>
//        /// <param name="splitButton"></param>
//        /// <param name="assemblyPath"></param>
//        /// <param name="code"></param>
//        /// <param name="buttonName"></param>
//        /// <param name="clsPath"></param>
//        /// <param name="imageSource"></param>
//        public void CreateSplitPushButton
//            (SplitButton splitButton, string assemblyPath, string code, string buttonName, string clsPath, ImageSource imageSource)
//        {
//            try
//            {
//                PushButton _PushButton =
//                   splitButton.AddPushButton(new PushButtonData(code + " " + buttonName,
//                    buttonName,
//                   assemblyPath, clsPath));
//                _PushButton.ToolTip = buttonName;
//                //_PushButton.LargeImage = Func.ChangeBitmapToImageSource(Resource.ICON_ALL);
//                // imageSource= Func.ChangeBitmapToImageSource(Resource.ICON_ALL);
//                _PushButton.LargeImage = imageSource;
//            }
//            catch (Exception exp)
//            { }

//        }

//        /// <summary>
//        /// 自删除工具 若插件根目录有文件  DELETE_ADDIN   则删除 addin 指定文件
//        /// </summary>
//        /// <param name="addinPath"></param>
//        private void DeleteAddin(string addinPath)
//        {
//            string checkFile = Path.Combine(assemblyDir, "DELETE_ADDIN");
//            //若不存在则不继续删除     DELETE_ADDIN文件存在则删除 
//            if (!File.Exists(checkFile))
//            { return; }
//            if (File.Exists(addinPath))
//            {
//                File.Delete(addinPath);
//            }
//        }

//        /// <summary>
//        /// 从资源内获取图片作为图标使用
//        /// </summary>
//        /// <param name="image"></param>
//        /// <returns></returns>
//        public ImageSource GetImageSource(Bitmap image)
//        {

//            //Bitmap image = Resource.ICON_ALL;

//            ImageSource imageSource = Imaging.CreateBitmapSourceFromHBitmap(
//                image.GetHbitmap(),
//                IntPtr.Zero,
//                Int32Rect.Empty,
//                BitmapSizeOptions.FromEmptyOptions());

//            return imageSource;
//        }

//        /// <summary>
//        /// 获得dll的绝对路径
//        /// </summary>
//        /// <param name="dllName"></param>
//        /// <returns></returns>
//        public string GetDllPath(string dllName)
//        {
//            string newStr = string.Empty;
//            newStr = Path.Combine(assemblyDir, dllName);
//            return newStr;
//        }

//    }
//}
